<template>
  <div class="detailbox">
    <div class="flexbox">
      <div class="shrinkbox_v2">
        账号
      </div>
      <div class="contentbox_v2">
        <el-input autocomplete="new-password" v-if="!feildConfig.isReadonly" class="diyinput" v-model="editData.userName" placeholder="请输入账号"></el-input>
        <div v-else class="div_input">
          {{ editData.userName }}
        </div>
      </div>
      <div class="shrinkbox_v2">
        密码
      </div>
      <div class="contentbox_v2">
        <el-input autocomplete="new-password" v-if="!feildConfig.isReadonly" :type="optype=='add'?'':'password'" class="diyinput" v-model="editData.passWord" 
         placeholder="请输入密码"></el-input>
        <div v-else class="div_input">
          {{ editData.passWord }}
        </div>
      </div>
    </div>
    <div class="flexbox">
      <div class="shrinkbox_v2">
        昵称
      </div>
      <div class="contentbox_v2">
        <el-input v-if="!feildConfig.isReadonly" class="diyinput" v-model="editData.nickName" placeholder="请输入昵称"></el-input>
        <div v-else class="div_input">
          {{ editData.nickName }}
        </div>
      </div>
      <div class="shrinkbox_v2">
        性别
      </div>
      <div class="contentbox_v2 diydatapicker">
        <el-select v-if="!feildConfig.isReadonly" v-model="editData.sex" class="diyselect" placeholder="请选择性别">
          <el-option :value="1" label="男"/>
          <el-option :value="2" label="女"/>
        </el-select>
        <div v-else class="div_input">
          {{ editData.sex == 1?'男':'女' }}
        </div>
      </div>
    </div>

    <div class="flexbox">
      <div class="shrinkbox_v2">
        手机号
      </div>
      <div class="contentbox_v2">
        <el-input v-if="!feildConfig.isReadonly" :maxlength="11" class="diyinput" v-model="editData.phone" placeholder="请输入手机号"></el-input>
        <div v-else class="div_input">
          {{ editData.phone }}
        </div>
      </div>
      <div class="shrinkbox_v2">
        邮箱
      </div>
      <div class="contentbox_v2">
        <el-input v-if="!feildConfig.isReadonly" class="diyinput" v-model="editData.email" placeholder="请输入邮箱"></el-input>
        <div v-else class="div_input">
          {{ editData.email }}
        </div>
      </div>
    </div>

    <div class="flexbox">
      <div class="shrinkbox_v2">
        状态
      </div>
      <div class="contentbox_v2">
        <el-select v-if="!feildConfig.isReadonly" v-model="editData.state" class="diyselect" placeholder="请选择状态">
          <el-option :value="0" label="正常"/>
          <el-option :value="1" label="冻结"/>
        </el-select>
        <div v-else class="div_input">
          {{ editData.state == 0?'正常':'冻结' }}
        </div>
      </div>
      <div class="shrinkbox_v2">
        是否开启配比权限
      </div>
      <div class="contentbox_v2">
        <el-select v-if="!feildConfig.isReadonly" v-model="editData.isCanUsePB" class="diyselect" placeholder="请选择状态">
          <el-option :value="true" label="开启"/>
          <el-option :value="false" label="关闭"/>
        </el-select>
        <div v-else class="div_input">
          {{ editData.isCanUsePB == 0?'开启':'关闭' }}
        </div>
      </div>
    </div>

    <div class="flexbox">
      <div class="shrinkbox_v2">
        企业
      </div>
      <div class="contentbox_v2">
        <!-- <el-input v-if="!feildConfig.isReadonly" class="diyinput" readonly v-model="editData.enterpriseFullName" placeholder="请输入企业"></el-input> -->
        <div class="div_input">
          {{ editData.enterpriseFullName }}
        </div>
      </div>
      <div class="shrinkbox_v2">
        角色
      </div>
      <div class="contentbox_v2">
        <el-select multiple v-if="!feildConfig.isReadonly" v-model="editData.roleIds" class="diyselect" placeholder="请选择角色">
          <el-option v-for="(role, index) in roleList" :key="index" :value="role.value" :label="role.label"/>
        </el-select>
        <div v-else class="div_input">
          {{ editData.roleIds == 0?'开启':'关闭' }}
        </div>
      </div>
    </div>

    <div class="flexbox">
      <div class="shrinkbox_v2">
        个人简介
      </div>
      <div class="contentbox_v2">
        <el-input v-if="!feildConfig.isReadonly" type="textarea" class="diyinput" v-model="editData.introduction" placeholder="请输入个人简介"></el-input>
        <div v-else class="div_input">
          {{ editData.enterpriseFullName }}
        </div>
      </div>
    </div>

  </div>
</template>

<script setup>
  import { ref, inject, defineEmits } from 'vue'
  // import { useStore } from 'vuex'
  // 注入全局utils工具js
  const $utils = inject('$utils')
  const editData = ref({})
  const feildConfig = ref({
    isReadonly: false
  })
  // 子传父
  const emit = defineEmits([])

  const roleList = ref([])
  const optype = ref('')

  function initData(obj) {
    editData.value = obj.data ? obj.data : {}
    feildConfig.value = obj.feildConfig ? obj.feildConfig : feildConfig.value
    optype.value = obj.type?obj.type:'add'
    getRoleList()
  }

  function getRoleList() {
    $utils.post({
      url: '/api/Enterprise/GetRolesById',
      params: {
        id: editData.value.enterpriseId
      },
      ok: function (data) {
        roleList.value = data.data
      }
    })
  }


  function submitData() {
    $utils.post({
      url: '/Api/EntUser/DoSave',
      params: editData.value,
      showLoading: true,
      ok: function (res) {
        $utils.message({
          message: res.msg,
          type: 'success'
        })
        emit('close-dialog', false)
      }
    })
  }

  defineExpose({
    initData,
    submitData
  })

</script>

<style scoped>
.saveBtn {
  background-color: #4999FA;
  color: #fff;
  font-weight: normal;
  font-size: 14px;
  padding: 3px 10px;
  border-radius: 3px;
  margin-right: 10px;
}
.saveBtn:hover {
  /* background-color: #7BB8FB; */
  opacity: 0.8;
  cursor: pointer;
}
.split_title {
  background-color: #EBEEF5;
  font-size: 16px;
  height: 30px;
  align-items: center;
  font-family: '楷体';
  font-weight: bold;
  display: flex;
  position: relative;
}
.split_title_content {
  flex-grow: 1;
  text-align: center;
}
.split_title_btn {
  display: flex;
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  align-items: center;
}
.shrinkbox_v2 {
  width: 70px;
}
.diyinput :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diyselect :deep(.el-select__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diyselect :deep(.el-select__wrapper:hover){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
.diyselect :deep(.el-select__wrapper:active){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
/* .diyselect :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
  pointer-events: none; 
}
.diyselect :deep(.el-input__wrapper:hover){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
.diyselect :deep(.el-input__wrapper:active){
  border: 0 !important;
  outline: none;
  box-shadow: none;
} */
.diyinput :deep(.el-textarea__inner){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diydatepicker :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
  font-size: 12px;
}
.diyformitem {
  margin-bottom: 0;
}
.diydatapicker :deep(.el-date-editor){
  width: 100%;
}
.diydatapicker :deep(.el-input__wrapper){
  border: 0 !important;
  outline: none;
  box-shadow: none;
}
.diyinput :deep(.el-input-group__append){
  border: 0 !important;
  outline: none;
  background-color: unset;
  box-shadow: none;
  padding: 0 10px 0 5px;
  font-weight: bold;
  font-size: 16px;
}
/deep/ input::-webkit-outer-spin-button,
/deep/ input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
/deep/ input[type='number'] {
  -moz-appearance: textfield;
}
</style>